package com.ruoyi.system.service.impl;

import java.util.List;

import com.ruoyi.common.utils.StringUtils;
import com.ruoyi.system.domain.HolidaySettings;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;
import com.ruoyi.system.mapper.HolidaySettingsMapper;
import com.ruoyi.system.service.IHolidaySettingsService;
import org.springframework.transaction.annotation.Transactional;

/**
 * 节假日、考勤设置Service业务层处理
 * 
 * @author yuan
 * @date 2022-09-25
 */
@Service
public class HolidaySettingsServiceImpl implements IHolidaySettingsService
{
    @Autowired
    private HolidaySettingsMapper holidaySettingsMapper;

    /**
     * 查询节假日、考勤设置
     * 
     * @param id 节假日、考勤设置主键
     * @return 节假日、考勤设置
     */
    @Override
    public HolidaySettings selectHolidaySettingsById(Long id)
    {
        return holidaySettingsMapper.selectHolidaySettingsById(id);
    }

    /**
     * 查询节假日、考勤设置列表
     * 
     * @param holidaySettings 节假日、考勤设置
     * @return 节假日、考勤设置
     */
    @Override
    public List<HolidaySettings> selectHolidaySettingsList(HolidaySettings holidaySettings)
    {
        return holidaySettingsMapper.selectHolidaySettingsList(holidaySettings);
    }

    /**
     * 更新节假日设置
     * 
     * @param holidaySettings 节假日、考勤设置
     * @return 结果
     */
    @Override
    @Transactional
    public int saveHolidaySettings(HolidaySettings holidaySettings)
    {
        //判断数据库是否有该日期的记录
        if(holidaySettings.getId() != null) {
            HolidaySettings oldHolidaySettings = holidaySettingsMapper.selectHolidaySettingsById(holidaySettings.getId());
            if (oldHolidaySettings != null) {
                oldHolidaySettings.setHolidayName(holidaySettings.getHolidayName());
                oldHolidaySettings.setIsHoliday(holidaySettings.getIsHoliday());
                return holidaySettingsMapper.updateHolidaySettings(oldHolidaySettings);
            }
        }
        return holidaySettingsMapper.insertHolidaySettings(holidaySettings);
    }

    /**
     * 修改节假日、考勤设置
     * 
     * @param holidaySettings 节假日、考勤设置
     * @return 结果
     */
    @Override
    public int updateHolidaySettings(HolidaySettings holidaySettings)
    {
        return holidaySettingsMapper.updateHolidaySettings(holidaySettings);
    }

    /**
     * 批量删除节假日、考勤设置
     * 
     * @param ids 需要删除的节假日、考勤设置主键
     * @return 结果
     */
    @Override
    public int deleteHolidaySettingsByIds(Long[] ids)
    {
        return holidaySettingsMapper.deleteHolidaySettingsByIds(ids);
    }

    /**
     * 删除节假日、考勤设置信息
     * 
     * @param id 节假日、考勤设置主键
     * @return 结果
     */
    @Override
    public int deleteHolidaySettingsById(Long id)
    {
        return holidaySettingsMapper.deleteHolidaySettingsById(id);
    }

    @Override
    public List<HolidaySettings> selectHolidaySettingsListByTime(String str) {
        return holidaySettingsMapper.selectHolidaySettingsListByTime(str);
    }
    /**
     * 根据yyyy-MM-dd查询当天的假期名称
     * @param str
     * @return
     */
    @Override
    public HolidaySettings selectHolidaySettingsListByDate(String str) {
        return holidaySettingsMapper.selectHolidaySettingsListByDate(str);
    }

    @Override
    public int selectHolidayCountBetweenStartTimeAndEndTime(String startTime, String endTime) {
        return holidaySettingsMapper.selectHolidayCountBetweenStartTimeAndEndTime(startTime,endTime);
    }
}
